// 模糊查询获取个人信息
import axios from 'axios';

// name, phone, idNumber 至少传一个
export async function getPersonInfo(name, phone, idNumber) {
    const ret = [];
    await axios.post("/api/caseInformation/getCaseInformation", {
        executor: name || "",
        phone: phone || "",
        idNumber: idNumber || "",
    })
    .then(response => {
        const result = response.data || [];
        // 根据身份证号去重
        const map = new Map();
        result.forEach(item => {
            item.idNumber = item.idNumber.trim();
            item.phone = item.phone.trim();
            item.executor = item.executor.trim();
            if (!map.has(item.idNumber)) {
                map.set(item.idNumber, item);
            }
        });
        // 取出去重后的结果
        map.forEach(item => {
            ret.push(item);
        });
    })
    .catch(error => {
        console.log('error', error);
    });
    return ret;
}